package com.z.demo

import com.z.demo.filter.NullFilter
import org.apache.flink.streaming.api.scala._

/**
 * @Author wenz.ma
 * @Date 2021/10/26 13:15
 * @Desc socket word count 最简单的代码
 */
object SocketWordCount {
  def main(args: Array[String]): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    //从socket获取流
    val inputStream = env.socketTextStream("server110", 9999)
    val resultStream = inputStream
      .flatMap(_.split(" "))//根据空格打散数据
      .filter(NullFilter)//过滤为空的数据
      .map((_, 1))//给每个词加个1
      .keyBy(x => {
        x._1//根据第一个字段分组
      }).sum(1)//下标从0开始，汇总第二个值

    resultStream.print("test")

    env.execute("socket word count")
  }
}
